package com.wang.interview.tests.gc;

import java.util.concurrent.TimeUnit;

/**
 * @author: wang
 * @date: 2021/8/5 20:01
 * @description:
 */
public class ReferenceChange {
    public static void main(String[] args) throws InterruptedException {
        A a = new A();
        a.setA(1);
        a = new A();
        a.setA(2);
        a = new A();
        a.setA(3);
        System.gc();
        TimeUnit.SECONDS.sleep(60);
    }
}

class A{
    int a = 0;

    public A(){
        System.out.println("开始了");
    }

    public void setA(int a) {
        this.a = a;
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println(a + "  A被回收了");
    }
}
